<template>
    <div>
        <div style="margin: 100px auto; width: 80%; font-size: 22px; text-align: center">登录中，请稍后。。。</div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            code: this.$route.query.code,
            base_url: 'http://127.0.0.1:8000'
        }
    },
    methods: {
        // 获取accesstoken
        getAaccessToken() {
            // 发送请求
            axios({
                url: this.base_url + '/app01/access_token/?code=' + this.code
            }).then(res => {
                console.log(res.data)
                if(res.data.code == 200) {
                    // 登录成功，保存session
                    localStorage.setItem('token', res.data.token)
                    // 登录成功，跳转到首页
                    this.$router.push({
                        name: 'Index'
                    })
                }else{
                    // 未绑定用户表的三方用户，去跳转到用户绑定页面
                    this.$router.push({
                        name: 'UserBind',
                        query: {'uid': res.data.uid}
                    })
                }
            })
        }

    },
    created() {
        this.getAaccessToken()
        console.log(this.$route.query.code)
    }
}
</script>

<style scoped>

</style>
